Namespace
std::cin use the name from the namespace std.using namespacename::name;
after the using declaration we can use the name directly.
A Separate using Declaration Is Required for Each Name
Each using declaration introduces a single namespace member
initialization of string
os<< s Write s onto output stream os.return os.
is>> s Reads whitespace-seperated string from is into s.return is.
getline(is,s) Reads a line of input from is to s.return is.
s.empty() Returns true if s is empty; otherwise returns false.
s.size() Returns the number of characters in s.
s[n] Returns a reference to the char at position n in s;position start at 0.
s1+s2 Returns a string that is concatenation of s1 and s2.
!= ,<,<=,>,>= Comparisons are case-sensitive and use dictionary.
getline() reads to (including)the first newline,but not store in the string.
empty:member function of string``return bool
size()return string::size_type
always use auto or decltype to let the compiler to provide the approriate
|
|
the range for statement
|
|
|
|
two ways to access individual characters in a stringsubscript or iterator
Any time we use a subscript, we must ensure that there is a value at the given location
vector
:contaner
class template
Vector is a template, not a type. type generated from vector must include the element type.for example vector
Vector initialize
The subscript operator on vector (and string) fetches an existing element; it does not add an element.
Iterators
:indirect access to an object
the iterator returned from end does not denote an element
The arrow operator combines dereference and member access into a single operation. That is, it->mem is a synonym for (\ it).mem*.
Iterators for string and vector support additional operations that can move an iterator multiple elements at a time and all the relational operators
Arrays
elements in an array default initialized
Array can`t be intialized by copy and assignment.
operations on arrays are often really operations on pointers such as auto.
but when we use decltype, The type returned by decltype(ia) is array of ten ints:
Unlike subscripts for vector and string, the index of the built-in subscript operator is not an unsigned type
c styled string function such as strlen() strcmp() strcat() strcpy() are not verify to string parameter.
c_str() indicates that the function returns a C-style character string
it returns a pointer to the beginning of a null-terminated character array that holds the same data as the characters in the string
The parentheses in this declaration are essential